from flask import Flask
import redis
import config
from views import index


class AI(Flask):
    def __init__(self, app_name, *args, **kwargs):
        super(AI, self).__init__(app_name, *args, **kwargs)
        self.get_db()
        self.get_redis()
        self.conf = config
        self.init_views()

    def get_redis(self):
        rdp = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
        self.redis = redis.StrictRedis(connection_pool=rdp)

    def get_db(self):
        pass

    def init_views(self):
        self.add_url_rule('/', view_func=index.IndexView.as_view('index'))
        self.add_url_rule('/check_task', view_func=index.TaskView.as_view('task'))
        self.add_url_rule('/upload_audio', view_func=index.UploadView.as_view('upload'))
